package bartek.tablice;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JProgressBar;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class SixpackGUI extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel contentPane;

	@SuppressWarnings("unused")
	public static void main(String[] args) {
		Sixpack sixPack = new Sixpack("Warka");
		SixpackGUI frame = new SixpackGUI(sixPack);
				
	}

	public SixpackGUI(final Sixpack sixPack) {
		setResizable(false);
		setTitle("SixpackGUI");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 135);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		final JProgressBar progressBar = new JProgressBar();
		progressBar.setBounds(10, 36, 424, 27);
		progressBar.setMinimum(0);
		progressBar.setMaximum(sixPack.stan());
		progressBar.setValue(sixPack.stan());
		contentPane.add(progressBar);
		
		JLabel lblIloPenychPiw = new JLabel("Ilo\u015B\u0107 pe\u0142nych piw: ");
		lblIloPenychPiw.setFont(new Font("Tahoma", Font.BOLD, 14));
		lblIloPenychPiw.setBounds(145, 11, 129, 14);
		contentPane.add(lblIloPenychPiw);
		
		final JLabel label = new JLabel(Integer.toString(sixPack.stan()));
		label.setFont(new Font("Tahoma", Font.BOLD, 14));
		label.setBounds(279, 11, 155, 14);
		contentPane.add(label);
		
		final JButton btnNewButton = new JButton("Pijemy !!");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				sixPack.wezPiwo();
				if(sixPack.stan() == 0){
					btnNewButton.setEnabled(false);
					label.setText("0 :( KONIEC PICIA !");
				}else
					label.setText(Integer.toString(sixPack.stan()));
				progressBar.setValue(sixPack.stan());
			}
		});
		btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 13));
		btnNewButton.setBounds(177, 74, 89, 23);
		contentPane.add(btnNewButton);
		this.setVisible(true);
	}
}
